﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace RedPanda.MusicPlayer.DataModel
{
    /// <summary>
    /// 该类用来记录当前播放的曲目的信息，用于绑定至UI，从而
    /// 实现UI的自动更新;
    /// </summary>
    public class CurrentTrackInfo :INotifyPropertyChanged
    {

        #region Fileds
        private string title;
        private string artist;
        private string album;
        private double duration;
        private double playedTime;
        private string gerne;
        private string year;
        #endregion

        #region Event
        public event PropertyChangedEventHandler PropertyChanged;
        #endregion


        #region Construtor
        public CurrentTrackInfo(string title, string artist, string album, double duration,
            string gerne, string year)
        {
            this.title = title;
            this.artist = artist;
            this.album = album;
            this.gerne = gerne;
            this.duration = duration;
            this.year = year;
            this.playedTime=0.0;

        }


        public CurrentTrackInfo()
        {
            title = String.Empty;
            artist = String.Empty;
            album = String.Empty;
            gerne = String.Empty;
            duration = 0.0;
            playedTime = 0.0;
        }

        /// <summary>
        /// 给定一个AudioFile对象生成CurrentTrackInfo
        /// </summary>
        /// <param name="af"></param>
        public CurrentTrackInfo(AudioFile af):
            this(af.Title,af.Artist,af.Album,af.Duration,af.Genre,af.Year)
        {
        }

        #endregion


        public string Title{
            get{
                return title;
            }
            set{
                if(!(title.Equals(value)))
                {
                    title=value;
                    this.Notify("Title");
                }
            }
        }

        public string Album{
            get{
                return album;
            }
            set{
                if(!(album.Equals(value)))
                {
                    this.album=value;
                    this.Notify("Album");
                }
            }
        }

        public string Artist{
            get{
                return artist;
            }
            set{
                if(!(artist.Equals(value)))
                {
                    artist=value;
                    this.Notify("Artist");
                }
            }
        }

        public string Gerne{
            get{
                return gerne;
            }
            set{
                if(!(gerne.Equals(value)))
                {
                    this.gerne=value;
                    this.Notify("Gerne");
                }
            }
        }

        public double Duration
        {
            get
            {
                return duration;
            }
            set
            {
                duration = value;
                this.Notify("Duration");
            }
        }

        public double PlayedTime
        {
            get
            {
                return playedTime;
            }
            set
            {
                playedTime = value;
                this.Notify("PlayedTime");
            }
        }

        public string Year
        {
            get
            {
                return year;
            }
            set
            {
                if (!(year.Equals(value)))
                {
                    year = value;
                    this.Notify("Year");
                }
            }
        }

        #region EventHandler
        private void Notify(string propertyName)
        {
            if(this.PropertyChanged!=null)
                this.PropertyChanged(this,new PropertyChangedEventArgs(propertyName));
        }
        #endregion
    }
}
